home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT9 / PARKING.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-27  |  6.2 KB  |  121 lines

  1. ;       Program Parking ( Chapter 9 )
  2. ;
  3.     page    55,132
  4. .model  tiny 
  5. .stack
  6. .data
  7. CR      equ     00Dh            ; Carriage return code
  8. LF      equ     00Ah            ; Line feed code
  9. EscScan equ     001h            ; Scan code for ESC key
  10. EndMsg  equ     024h            ; Dollar sign - end of message for DOS service
  11. Ten     db      10              ; Constant to convert binary to string
  12. StMsg   db      CR,LF,LF,'The Hard Disk Parking utility      06.04.1992'
  13.     db      '     Version 1.4', CR , LF
  14.     db      'Copyright (C) 1992 V.B.Maljugin,     Voronezh, Russia',CR,LF,LF
  15. Ndrives db      '0'
  16.     db      ' hard disk drive(s) found', CR, LF, EndMsg
  17. PrkMsg  db      CR,LF,'Heads of the hard disk drive '
  18. DrNum1  db      '/'
  19.     db      ' have been positioned at the cylinder ',EndMsg
  20. FinMsg  db      CR,LF,LF
  21.     db      'Turn off the power or press the ESC key to return to DOS'
  22.     db      CR,LF,LF,EndMsg
  23. LandZone        dw      0
  24. Drive           db      7Fh
  25. HexTab  db      '0' , '1' , '2', '3', '4' , '5', '6' , '7'
  26.     db      '8' , '9' , 'A', 'B', 'C' , 'D', 'E' , 'F'
  27.  
  28. .code                                   ; The CODE segment stars here
  29. .startup                                ; This is a standard prologue
  30.     org     100h
  31. ;===    Getting the number of drives installed
  32.     mov     cx,0                    ; Clear CX
  33.     mov     es,cx                   ; ES points to segment 0000h
  34.     mov     cl,es:[475h]            ; Get number of drives from BIOS area
  35.     add     Ndrives,cl              ; Form text for number of drives
  36. ;===    Outputting the initial message
  37.     lea     dx,StMsg                ; Address of message into DX
  38.     mov     ah,09                   ; Function 09h - output text string
  39.     int     21h                     ; Dos service call
  40. ;===    Checking whether there are drives to be processed
  41. ToNext: 
  42.     add     DrNum1,1                ; Text for message about parking
  43.     add     Drive,01h               ; Take the next disk drive 1    
  44.     mov     al,DrNum1               ; Load current drive number (char)
  45.     cmp     al,Ndrives              ; Compare it with the number of drives
  46.     jb      ProcDrives              ; If not all the drives - continue
  47.     jmp     Finish                  ; Otherwise proceed to the exiting
  48. ProcDrives:             ;===  Processing the current drive starts from here  ===
  49. ;===    Recalibrate the current drive
  50.     mov     ah,11h                  ; Function 11h - recalibrate drive
  51.     mov     dl,Drive                ; DL - drive number (80h for drive 1)
  52.     int     13h                     ; BIOS disk service call
  53.     jnc     DriveOK                 ; If recalibration successful - continue
  54.     jmp     ToNext                  ; If failed, proceed to the next drive
  55. ;===    Getting the maximum number of cylinders
  56. DriveOK:
  57.     mov     ah,08                   ; Function 08 - Get drive parameter
  58.     int     13h                     ; BIOS disk service
  59.     mov     al,ch                   ; Low part of maximum cylinder number
  60.     shl     cx,1                    ; Bit 7 of CL into bit 0 of CH
  61.     shl     cx,1                    ; Bits 6,7 of CL into bits 0,1 of CH
  62.     and     ch,3                    ; Bits 0,1 of CH will be used
  63.     mov     ah,ch                   ; Form maximum number of cylinder
  64.     add     ax,2                    ; One cylynder farther maximum
  65.     cmp     ax,1023                 ; Is it above 1023?
  66.     jle     le1023                  ; If not - process this number
  67. ;===    Replace the number of cylinders that is greater than 1023 with 1023     
  68.     mov     ax,1023                 ; If it is so - replace it with 1023
  69. ;===    Prepare input parameters for positioning the heads      
  70. le1023:                                 ;
  71.     mov     LandZone,ax             ; Store Landzone to be output
  72.     mov     ch,ah                   ; CH - low byte of cylinder number,
  73.     shr     cx,1                    ; Shift bits 0 and 1 of CH into
  74.     shr     cx,1                    ;    bits 6 and 7 of CL (high bits)
  75.     mov     ch,al                   ; Low bits of LandZone
  76. ;===    Positioning the heads
  77.     mov     ah,0Ch                  ; Function 0Ch - heads positioning
  78.     mov     dh,0                    ; Head number = 0
  79.     mov     dl,Drive                ; Drive number (80h for drive 0)
  80.     int     13h                     ; BIOS disk service call
  81. ;===    Outputting the message "parked at ..."
  82.     lea     dx,PrkMsg               ; Addres of message "parked" into DX
  83.     mov     ah,09                   ; Function 09h - output text string
  84.     int     21h                     ; Dos service call
  85. ;===    Convert the number of landing cylinder into text for printing
  86.     mov     ax,LandZone             ; Place number to be printed into AX.
  87.     mov     cx,0                    ; Initial value for counter of digits
  88. NexDiv:
  89.     div     byte ptr Ten            ; Division the number by 10. Result in
  90.                     ;    AL register and remainder in AH.
  91.     push    ax                      ; Push Remainder into stack.
  92.     mov     ah,0
  93.     inc     cx                      ; Increase counter
  94.     cmp     al,0                    ; Check if result is zero
  95.     jne     NexDiv                  ; If not, get the next digit
  96. ;===    Outputting the number of landing zone   
  97.     mov     ah,02h                  ; Function 02h - output symbol
  98. OutSym: pop     dx                      ; Pop next digit of result
  99.     mov     dl,dh                   ; Cypher into DL for output
  100.     add     dl,30h                  ; Convert it to character
  101.     int     21h                     ; Output it using DOS service
  102.     loop    OutSym                  ; Proceed to the next digit
  103.     
  104.     jmp     ToNext                  ; Proceed to the next drive processing
  105.     
  106. Finish:
  107.     lea     dx,FinMsg               ; Addres of message into DX
  108.     mov     ah,09                   ; Function 09h - output text string
  109.     int     21h                     ; Dos service call
  110. ;===    Waiting for a key pressed
  111. WaitKey:
  112.     mov     ax,0                    ; Function 00h - read character from keyboard
  113.     int     16h                     ; BIOS keyboard service call
  114.     cmp     ah,EscScan              ; Is the ESC key pressed?
  115.     jne     WaitKey                 ; If not - Wait for next key pressing
  116. ;===    Exit to DOS if necessary
  117.     mov     ax,4C00h                ; Function 4Ch - terminate process
  118.     int     21h                     ; DOS service call
  119.     end
  120.